#ifndef __JSON_NODE_H__
#define __JSON_NODE_H__

#include "SPtrArray.h"

class JsonNode
{
public:
	JsonNode();
	virtual ~JsonNode();
public:
	virtual void print(FILE * out,int level)=0;
	virtual int GetSize(){ return 0;}
	virtual const char * GetName() { return NULL; }
	virtual JsonNode * GetAt(int index){ return NULL; }
};
class TxtNode : public JsonNode
{
    char * value;
public:
	TxtNode();
	TxtNode(const char * s);
	virtual ~TxtNode();
public:
	virtual const char * GetName() { return value; }
	virtual void print(FILE * out,int level);
};

class PairNode : public JsonNode
{
    char * name;
    JsonNode * value;
public:
	PairNode();
	PairNode(const char * s);
	virtual ~PairNode();

	void SetValue(JsonNode * p) { value = p; }
	virtual int GetSize(){ return value->GetSize(); }
	virtual JsonNode * GetAt(int nIndex) { return (JsonNode *)value->GetAt(nIndex); }

public:
	virtual const char * GetName() { return name; }
	virtual void print(FILE * out,int level);
};

class BraceNode: public JsonNode
{
protected:
	CSPtrArray nodes;
public:
     BraceNode();
	 virtual ~BraceNode();

	 virtual int GetSize(){ return nodes.GetSize(); }
	 virtual JsonNode * GetAt(int nIndex) { return (JsonNode *)nodes.GetAt(nIndex); }

	 JsonNode * Add(JsonNode * node) { nodes.Insert(node); return node; }

	 virtual void print(FILE * out,int level);
};
class SquareNode: public BraceNode
{
public:
     SquareNode();
	 virtual ~SquareNode();

	 virtual void print(FILE * out,int level);
};

#endif

